layui.define(['table', 'form'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form;

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/member/order/list.data'
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
      {field: 'tradeNo', title: '订单号'}
      ,{field: 'businessTypeName',title: '业务类型'}
      ,{field: 'placeName', title: '网点信息',templet:function (record){
          return record.placeName + '('+record.placeId+')';
      }}
      ,{field: 'deviceFunCodeName',title: '设备功能'}
      ,{field: 'deviceSn',title: '设备序列号'}
      ,{field: 'memberName', title: '会员昵称'}
      ,{field: 'moneyStr',title: '订单金额'}
      ,{field: 'payInfo',title: '实际支付'}
      ,{field: 'discountMoneyStr',title: '优惠金额'}
      ,{field: 'stateName',title: '订单状态',templet:function (record){
              if(record.state == 1){
                  return '<span class="layui-badge layui-bg-green">'+record.stateName+'</span>';
              }else if(record.state == 4){
                  return '<span class="layui-badge">'+record.stateName+'</span>';
              }else{
                  return record.stateName;
              }
          }}
      ,{field: 'divideStateName',title: '分成状态',templet:function (record){
              if(record.divideState == 3){
                  return '<span class="layui-badge layui-bg-green">'+record.divideStateName+'</span>';
              }else if(record.divideState == 4){
                  return '<span class="layui-badge">'+record.divideStateName+'</span>';
              }else{
                  return record.divideStateName;
              }
          }}
      ,{field: 'createDate', title: '创建时间', sort: true}
      ,{title: '操作', width: 200, align:'center', fixed: 'right', templet:function(record){
          var html = '';
          html = html + '<a class="layui-btn layui-btn-xs" lay-event="info">查看</a>';
          html = html + '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="operate">操作</a>';
          html = html + '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="profit">分成信息</a>';
          return html;
      }}
    ]]
    ,page: true
    ,limit: 30
    ,height: 'full-220'
    ,text: '对不起，加载出现异常！'
  });
  
  //监听搜索
  form.on('submit(LAY-search)', function(data){
    var field = data.field;
    //执行重载
    table.reload('LAY-table', {
      where: field
    });
  });
  
  //事件
  var active = {
      info:function(obj) {
          layer.open({
              type: 2
              , title: '查看业务订单详情'
              , content: layui.setter.webRoot + '/member/order/info.html?tradeNo=' + obj.data.tradeNo+'&createDate='+obj.data.createDate
              , maxmin: true
              , area: ['90%', '90%']
          })
      }
      ,operate:function(obj) {
          layer.open({
              type: 2
              , title: '操作业务订单'
              , content: layui.setter.webRoot + '/member/order/operate.html?tradeNo=' + obj.data.tradeNo+'&createDate='+obj.data.createDate
              , maxmin: true
              , area: ['90%', '90%']
          })
      }
      ,profit:function(obj) {
          layer.open({
              type: 2
              , title: '查看业务订单分成'
              , content: layui.setter.webRoot + '/member/order/profit.html?tradeNo=' + obj.data.tradeNo+'&createDate='+obj.data.createDate
              , maxmin: true
              , area: ['90%', '90%']
          })
      }
  };
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('member_order_business_list', {})
});